/* Archive Extractor
 * Copyright 2008-2009 Matthew Hoops
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * $URL: http://archive-extractor.googlecode.com/svn/trunk/ms_cab.cpp $
 * $Id: ms_cab.cpp 2 2009-03-23 01:29:43Z clone2727 $
 *
 */

#include "ms_cab.h"

MicrosoftCabinet::MicrosoftCabinet() : StandardArchive() {
}

std::vector<const char*> MicrosoftCabinet::getArchiveExtensions() {
	std::vector<const char*> exList;
	exList.push_back("cab");
	return exList;
}

int MicrosoftCabinet::detect(FILE* file) {
	if (readUint32BE(file) != 'MSCF')
		return 0;
	return 100;
}

bool MicrosoftCabinet::extractFiles(FILE* file) {
	readUint32BE(file); // Already checked ;)
	/* uint32 checkSum = */ readUint32LE(file);
	/* uint32 fileSize = */ readUint32LE(file);
	/* uint32 foldersCheckSum = */ readUint32LE(file);
	uint32 cabEntryOffset = readUint32LE(file);
	/* uint32 filesCheckSum = */ readUint32LE(file);
	uint16 version = readUint16LE(file);
	if (version != 0x103) {
		printf ("Unsupported Microsoft Cabinet version 0x%04x\n", version);
		return false;
	}
	uint16 folderCount = readUint16LE(file);
	uint16 fileCount = readUint16LE(file);
	uint16 flags = readUint16LE(file);
	/* uint16 cabId = */ readUint16LE(file);
	/* uint16 cabNum = */ readUint16LE(file);
	
	return false;
}
